package cn.tedu.egaddress.controller;

import cn.tedu.egaddress.mapper.AddressMapper;
import cn.tedu.egaddress.pojo.dto.AddressAddParam;
import cn.tedu.egaddress.pojo.vo.AddressInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/address/")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;

    @PostMapping("add")
    public String add(@RequestBody AddressAddParam addressAddParam){
        System.out.println("addressAddParam = " + addressAddParam);
        int rows = addressMapper.insertAddress(addressAddParam);
        if (rows > 0){
            return "恭喜你,添加地址成功";
        } else {
            return "添加地址失败";
        }
    }

    @GetMapping("list")
    public List<AddressInfoVO> list(){
        return addressMapper.list();
    }

    @PostMapping("del/{addressId}")
    public String delete(@PathVariable Integer addressId){
        System.out.println("addressId = " + addressId);
        int rows = addressMapper.deleteAddressById(addressId);
        if (rows > 0){
            return "恭喜你,删除地址成功";
        } else {
            return "删除地址失败";
        }
    }
}







